﻿
@{
    ViewBag.Title = "Index";
    ViewBag.First = "车辆管理";
    ViewBag.Second = "车辆报废列表";
    Layout = "~/Views/Shared/_BaseLayout.cshtml";
    var list = ViewData["olist"] as IList<Sc.Domain.CommOrgz>;
}
<script src="~/Content/laydate-v1.1/laydate/laydate.js"></script>
<script src="~/Content/laypage-v1.3/laypage/laypage.js"></script>
<script type="text/javascript">
    $(document).ready(function (e) {
        initDate("start", "end", "YYYY/MM/DD");
        $("#selOrgz").uedSelect({
            width: 120
        });
        loadData(1, 1);
    });
    //数据加载
    function loadData(curr, tag) {
        var url = '@Url.Action("GetPageData")';
        var load = loadTip("数据加载中，请稍候", 16, 0);
        $.get(url, { pageSize: 10, pageIndex: curr, orgz: $("#selOrgz").val(), start: $("#start").val(), end: $("#end").val(), carNo: $("#txtCarNo").val() }, function (data) {
            $("#listData").find("tr").remove();
            if (tag == 1) {
                initPage(data.PageCount, 1);
                $("#recordCount").html(data.RecordCount);
            }
            var table = document.getElementById("listData");
            $.each(data.Data, function (index, n) {
                var row = table.insertRow(table.rows.length);
                row.insertCell(0).innerHTML = "<input type='checkbox' tag=" + n.Id + " />";
                row.insertCell(1).innerHTML = n.CarNo;
                row.insertCell(2).innerHTML = n.OrgzName;
                row.insertCell(3).innerHTML = ChangeDateFormat(n.ScrapTime, 1);
                row.insertCell(4).innerHTML = ChangeDateFormat(n.RegistrationTime, 1);
                row.insertCell(5).innerHTML = n.ServiceLife + "年";
                row.insertCell(6).innerHTML = n.ResidualValue + "%";
                row.insertCell(7).innerHTML = fmoney(n.ResidualAmount, ",");
                row.insertCell(8).innerHTML = n.ScrapAddress;
                row.insertCell(9).innerHTML = n.ScrapReson;
                row.insertCell(10).innerHTML = '<a href="javascript:void(0);" onclick="edit(' + n.Id + ');" class="tablelink">修改</a><a href="javascript:void(0);" onclick="detail(' + n.Id + ');" style="margin-left:10px" class="tablelink">详情</a>';
            });
            $('.tablelist tbody tr:odd').addClass('odd');
            $("#currPage").html(curr);
            layer.close(load);
        });
    }
    //初始化分页
    function initPage(pageCount, curr) {
        laypage({
            cont: 'paginList',
            pages: pageCount,
            first: false,
            last: false,
            skip: true,
            curr: curr || 1,
            jump: function (e, first) {
                if (!first) {
                    loadData(e.curr)
                }
            }
        });
    }
    //添加检查登记记录
    function add() {
        window.location.href = "@Url.Action("CreateCarScrap")";
    }
    //修改记录
    function edit(id) {
        //var data = $("#listData tr").find("input[type=checkbox]:checked");
        //if (data.length <= 0) {
        //    loadTip("请至少选择一条数据进行修改", 2, 1000);
        //    return false;
        //}
        //if (data.length > 1) {
        //    loadTip("只能选择一条数据进行修改", 2, 1000);
        //    return false;
        //}
        window.location.href = "@Url.Action("UpdateCarScrap")?id=" + id;
    }
    //删除数据
    function del() {
        var data = $("#listData tr").find("input[type=checkbox]:checked");
        if (data.length <= 0) {
            loadTip("请至少选择一条数据进行删除", 2, 1000);
            return false;
        }
        layer.confirm("您确定要删除吗？", function () {
            var ids = "";
            for (var i = 0; i < data.length; i++) {
                if (i > 0) {
                    ids += ",";
                }
                ids += $(data[i]).attr("tag");
            }
            var url = "@Url.Action("DeleteCarScrap")";
            var load = loadTip("数据提交中，请稍候", 16, 0);
            $.get(url, { ids: ids }, function (data) {
                if (data > 0) {
                    layer.msg("数据删除成功", { icon: 1, time: 1000, shade: [0.3, '#000'] }, function () {
                        loadData(1, 1);
                    });
                } else {
                    loadTip("网络错误，请稍后再试", 2, 1000);
                }
            });
        });
    } 
    //详情查看
    function detail(id) {
        window.location.href = "@Url.Action("CarScrapDetail")?id=" + id;
    }
</script>
<div class="rightinfo">
    <div class="tools">
        <ul class="toolbar">
            <li class="click" onclick="add();"><span><img src="~/Content/images/t01.png" /></span>添加</li>
            @*<li class="click" onclick="edit();"><span><img src="~/Content/images/t02.png" /></span>修改</li>*@
            <li onclick="del();"><span><img src="~/Content/images/t03.png" /></span>删除</li>
        </ul>
        <input type="hidden" id="busId" value="0" />
        <ul class="seachform" style="float:right;">
            <li>
                <label>单位</label>
                <div class="vocation">
                    <select name="select" class="select2" id="selOrgz">
                        <option value="0">----请选择----</option>
                        @foreach (var item in list)
                        {
                            <option value="@item.Id">@item.OrgzName</option>
                        }
                    </select>
                </div>
            </li>
            <li>
                <label>车牌号</label>
                <input type="text" id="txtCarNo" style="width:110px" class="scinput" />
            </li>
            <li>
                <label>开始时间</label>
                <input type="text" id="start" style="width:110px" value="@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")" readonly="readonly" class="scinput" />
            </li>
            <li>
                <label>结束时间</label>
                <input type="text" style="width:110px" value="@DateTime.Now.AddDays(-DateTime.Now.Day + 1).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd")" id="end" readonly="readonly" class="scinput" />
            </li>
            <li>
                <label>&nbsp;</label>
                <input name="Input" type="button" class="scbtn" onclick="loadData(1,1);" value="查询" />
            </li>
        </ul>
    </div>
    <table class="tablelist">
        <thead>
            <tr>
                <th width="30px"></th>
                <th width="80">车牌号</th>
                <th width="160">所属单位</th>
                <th width="110">报废时间</th>
                <th width="110">登记时间</th>
                <th width="80">使用年限</th>
                <th width="60">残值率</th>
                <th width="110">残值金额</th>
                <th>报废地址</th>
                <th>报废原因</th>
                <th width="110">操作</th>
            </tr>
        </thead>
        <tbody id="listData"></tbody>
    </table>
    <div class="pagin">
        <div class="message" style="padding-top:5px;">共&nbsp;<i class="blue" id="recordCount"></i>&nbsp;条记录，当前显示第&nbsp;<i class="blue" id="currPage"></i>&nbsp;页</div>
        <ul class="paginList" id="paginList"></ul>
    </div>
</div>


